package sg.partying.lcb.android

import android.app.Activity
import android.graphics.Color
import android.os.Build
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.AppUtils
import com.blankj.utilcode.util.Utils
import com.bumptech.glide.Glide
import com.salton123.app.BaseApplication
import com.salton123.crash.XCrashManager
import com.salton123.soulove.CommonClassPath
import com.tencent.cloud.iai.lib.auth.Auth
import com.tencent.cloud.iai.lib.auth.Auth.AuthResult
import sg.partying.lcb.android.config.AppConfig
import sg.partying.lcb.android.config.ConfigProvider
import java.lang.String

/**
 * User: newSalton@outlook.com
 * Date: 2019/4/24 16:11
 * ModifyTime: 16:11
 * Description:
 */
class XApp : BaseApplication() {
    companion object {

        init {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
            }
            System.loadLibrary("YTSegmentation")
        }
    }

    var mAuthResult: AuthResult? = null
    override fun onCreate() {
        super.onCreate()
        AppUtils.registerAppStatusChangedListener(
            object : Utils.OnAppStatusChangedListener {
                override fun onForeground(activity: Activity?) {
                }

                override fun onBackground(activity: Activity?) {
                }
            }
        )
        Auth.setUseTestEnv(false)
//        Auth.auth(this, null /*填写你的lic文件名*/, "6xgt3op4c" /*填写你的AppID*/, "266130e68e834a37bd9ffe016a0706f3" /*填写你的KEY*/)
        Auth.auth(this, null /*填写你的lic文件名*/, "n93s48dxp" /*填写你的AppID*/, "50871d20223542649ca2bdc91cd15c95" /*填写你的KEY*/)
            .apply {
            if (this.isSucceed) {
                Log.e("XApp", "授权成功:${this.authInfo.authLicenseId}")
            } else {
                Log.e("XApp", "授权失败:${this.authResultFail.msg}")
            }
        }
        val configProvider = ConfigProvider()
        AppConfig.init(configProvider)

        if (CommonClassPath.isDebugAppMode) {
            ARouter.openLog()
            ARouter.openDebug()
        }
        ARouter.init(this)
        XCrashManager.init(this)
    }

    override fun onLowMemory() {
        super.onLowMemory()
        Glide.get(this).onLowMemory()
    }

    override fun onTrimMemory(level: Int) {
        super.onTrimMemory(level)
        Glide.get(this).onTrimMemory(level)
    }

}
